package com.academic_system.controller;

import com.academic_system.model.Teacher;
import com.academic_system.service.TeacherService;
import com.academic_system.util.Message;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 20155883 万珊
 * @description 老师控制层
 * @project_name TeacherController
 * @package com.academic_system.controller
 * @create 2018-05-17 14:33
 **/
@Controller
@RequestMapping("/teacher")
@ResponseBody
@CrossOrigin(origins = "*")
public class TeacherController {
    @Autowired
    TeacherService teacherService;

    /**
     * @Description 根据Teacher表中的老师编号查询老师个人信息

     * @methodName queryTeacherByTeNum
     * @param teNum
     * @returnType Message

     **/
    @RequestMapping(value = "/queryTeacher",method = RequestMethod.GET)
    public Message queryTeacherByTeNum(@Param("teNum")int teNum){
        return teacherService.queryTeacherByTeNum(teNum);
    }


    /**
     * @param teacher
     * @Description 修改老师信息表（姓名，性别，身份证，出生年月，民族，电话，籍贯）

     * @methodName updateTeacher
     * @returnType Message

     **/
    @RequestMapping(value = "/updateTeacher",method = RequestMethod.POST)
    public Message updateTeacher(@RequestBody Teacher teacher){
        return teacherService.updateTeacher(teacher);
    }

    @RequestMapping("/switchState")
    @ResponseBody
    public void removeMyProject(int project_id,int project_state, HttpServletResponse response) throws IOException {
        System.out.println("project_id:"+project_id);
        System.out.println("project_state:"+project_state);
        boolean flag = teacherService.switchState(project_state,project_id);
        PrintWriter out = response.getWriter();
        if (flag) {
            out.write("true");
        } else {
            out.write("false");
        }
    }
}
